import { useMount } from "utils";
import { useHttp } from "./http";
import { User } from "screens/project-list/search-panel";
import { useAsync } from "./use-async";

// param传递的参数都是Project类型中的部分属性，这里可以通过Partial取得
export const useUser = (param?: Partial<User>) => {
  const client = useHttp();
  const { run, ...result } = useAsync<User[]>();

  // 只有首次加载时获取一次，相当于ComponentDidMount
  useMount(() => {
    run(client("users"));
  });

  return result;
};
